package com.org.javabody.io.InputStream;

import java.io.*;

/**
 * 字节流
 * Created by admin on 2017/1/24.
 */
public class FileInputStreamDemo {

    public static void openFiles(String location) { //文件输入流
        int count = 0;
        File file = new File(location);
        InputStream inputStream = null;

        try {
            inputStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            System.out.println("找不到对应的文件！");
        }
        try {
            while(inputStream.read()!=-1) {  //读取文件字节，并递增指针到下一个字节,为-1时表示已读取到末尾结束
                    count++;
                }
            System.out.println("---长度是： "+count+" 字节---");
        } catch (IOException e) {
            e.printStackTrace();
        }

       finally {
            try {
                inputStream.close(); //无论是否成功读取，都要关闭IO缓冲区
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
            openFiles("F:/background.jpg");
    }
}
